#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
Python 3.x
Flask 2.1.3
Flask-Migrate 3.1.0

Official Manual Address : https://flask-migrate.readthedocs.io/en/latest/

"""
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from constants import DB_URI

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = DB_URI
db = SQLAlchemy(app)
# 绑定app和数据库
migrate = Migrate(app, db)


class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20))
    addresses = db.relationship('Address', backref='user')


class Address(db.Model):
    __tablename__ = 'address'
    id = db.Column(db.Integer, primary_key=True)
    email_address = db.Column(db.String(50))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))


@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run()
